using System;
using System.Threading;
using System.Threading.Tasks;
using CHEnhanceEfCore.Config.MQ.factory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace CHEnhanceEfCore.Config.MQ
{
    public class MqService : BackgroundService
    {
        private readonly IServiceProvider _serviceProvider;

        public MqService(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var mqFactory = _serviceProvider.GetService<RabbitMqFactory>();
            mqFactory?.init();

            return Task.CompletedTask;
        }
    }
}